package com.chuanyang.driverh.mainmy.adapter;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.chuanyang.driverh.R;
import com.chuanyang.driverh.base.OnCustomListener;
import com.chuanyang.driverh.responseresult.CarTeamData;
import com.chuanyang.driverh.utils.BitmapUtil;

import java.util.List;


public class AddCarTeamAdapter extends BaseAdapter {
    private Context context;
    private OnCustomListener listener;


    public void setList(List<CarTeamData.DataBean> list) {
        this.list = list;
       // this.isCarTeam=isCarTeam;
        this.notifyDataSetChanged();
    }

    private List<CarTeamData.DataBean> list;
    private ViewHolder holder;

    public AddCarTeamAdapter(Context context, List<CarTeamData.DataBean> list) {
        this.context = context;
        this.list = list;
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.my_item_addcarteam, null);
            holder = new ViewHolder();
            holder.iv_addcarteam_icon = (ImageView) convertView.findViewById(R.id.iv_addcarteam_icon);
            holder.tv_addcarteam_name = (TextView) convertView.findViewById(R.id.tv_addcarteam_name);
            holder.tv_addcarteam_teamcode = (TextView) convertView.findViewById(R.id.tv_addcarteam_teamcode);
            holder.tv_addcarteam_leadername = (TextView) convertView.findViewById(R.id.tv_addcarteam_leadername);
            holder.tv_addcarteam_add = (TextView) convertView.findViewById(R.id.tv_addcarteam_add);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        CarTeamData.DataBean bean = list.get(position);
        BitmapUtil.showImgForNetPath(bean.getLeaderImage(),holder.iv_addcarteam_icon);
//        YncApplication.getInstance().loadCircleImage(context, bean.getLeaderImage(), R.drawable.shengfeng, R.drawable.shengfeng, holder.iv_addcarteam_icon);
        holder.tv_addcarteam_name.setText(bean.getFleetName());
        holder.tv_addcarteam_teamcode.setText(bean.getId() + "");
        holder.tv_addcarteam_leadername.setText(bean.getLeaderName());


        holder.tv_addcarteam_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onCustomerListener(holder.tv_addcarteam_add, position);
                }
            }
        });

        return convertView;
    }

    private class ViewHolder {
        ImageView iv_addcarteam_icon;
        TextView tv_addcarteam_name;
        TextView tv_addcarteam_teamcode;
        TextView tv_addcarteam_leadername;
        TextView tv_addcarteam_add;
    }

    /**
     * 设置适配器上，某个控件的监听事件
     *
     * @param listener
     */
    public void setOnCustomListener(OnCustomListener listener) {
        this.listener = listener;
    }
}
